<template>
  <div class="qr-code-modal" @click="close">
    <div class="qr-code-content" @click.stop>
      <h3>{{ title }}</h3>
      <img :src="qrCodeSrc" alt="APP下载二维码" class="qr-code-image">
      <p>{{ description }}</p>
      <button class="close-btn" @click="close">{{ closeText }}</button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'QrCodeModal',
  props: {
    title: {
      type: String,
      default: '扫码下载APP',
    },
    qrCodeSrc: {
      type: String,
      default: 'https://placehold.co/200x200/4CAF50/FFFFFF?text=APP+QR+Code',
    },
    description: {
      type: String,
      default: '扫码立即下载视界无界APP',
    },
    closeText: {
      type: String,
      default: '关闭',
    },
  },
  mounted() {
    // 监听ESC键关闭弹窗
    document.addEventListener('keydown', this.handleEscKey)
  },
  beforeUnmount() {
    document.removeEventListener('keydown', this.handleEscKey)
  },
  methods: {
    close() {
      this.$emit('close')
    },
  },
}
</script>

<style scoped>
.qr-code-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.qr-code-content {
  background-color: var(--background-primary, #18181b);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  border: 1px solid var(--border-light, #3f3f46);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  max-width: 300px;
  width: 90%;
  animation: slideUp 0.3s ease;
}

.qr-code-content h3 {
  color: var(--text-primary, #f4f4f5);
  margin-bottom: 20px;
  font-size: 20px;
}

.qr-code-image {
  border: 4px solid var(--text-primary, #f4f4f5);
  border-radius: 8px;
  margin-bottom: 16px;
  width: 200px;
  height: 200px;
}

.qr-code-content p {
  color: var(--text-secondary, #a1a1aa);
  margin-bottom: 20px;
  font-size: 14px;
}

.close-btn {
  background-color: var(--primary-color, #00a1d6);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.3s ease;
}

.close-btn:hover {
  background-color: var(--primary-hover, #0086c3);
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* 响应式调整 */
@media (max-width: 480px) {
  .qr-code-content {
    padding: 20px;
  }
  
  .qr-code-image {
    width: 180px;
    height: 180px;
  }
  
  .qr-code-content h3 {
    font-size: 18px;
  }
}
</style>